﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net.Sockets;
using System.Text;
using System.Collections.Generic;

namespace Memceched
{
    public partial class MemcacheInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string[] serverList = {"192.168.6.213","192.168.6.213"};
            NetworkStream ns;
            TcpClient tc = new TcpClient("59.151.102.126", 11211);
            ns = tc.GetStream();
            byte[] wBuf = Encoding.ASCII.GetBytes("stats\r\n");
            ns.Write(wBuf, 0, wBuf.Length);
            byte[] rBuf = new byte[4096];
            int length = ns.Read(rBuf, 0, rBuf.Length);
            string backStr = Encoding.ASCII.GetString(rBuf, 0, length);
            Dictionary<string,string> keyValue = new Dictionary<string,string>();
            foreach (string s in backStr.Replace("\r\nEND\r\n","").Replace("\r\n", "|").Split('|'))
            {
                keyValue.Add(s.Split(' ')[1], s.Split(' ')[2]);
            }
            ltlMaxCache.Text = (Convert.ToInt32(keyValue["limit_maxbytes"])/1024/1024).ToString();
            ltlUsed.Text = keyValue["bytes"];
            rptMem.DataSource = serverList;
            rptMem.DataBind();
            ns.Close();
            ns.Dispose();
        }
    }
}
